﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "ActionBase.h"
#include "Vector3d.h"

namespace gcmp
{
    class ISnapSettings;
}

namespace Sample
{
    //绘制墙体
    class ActionDrawWall : public gcmp::ActionBase
    {
        enum DrawStatus
        {
            eWait,
            eGetting_StartPoint,
            eGetting_EndPoint
        };

    public:
        ActionDrawWall();

        virtual ~ActionDrawWall();

        virtual bool PreviewKeyEvent() override;
        virtual bool OnKeyDown(gcmp::IUiView* pCurrentView, int nChar) override;
        bool GetCtrlKeyPressed();
    protected:
        virtual void EnterGettingStartPointState(gcmp::IUiView* pCurrentView);
        virtual void EnterGettingEndPointState(gcmp::IUiView* pCurrentView);
        virtual void OnChildActionFinished(gcmp::IUiView* pCurrentView, const gcmp::ActionOutput& childActionReturnParam) override;

        virtual gcmp::ElementId OnDrawFinished(gcmp::IUiView* pCurrentView, const gcmp::Vector3d& startPt, IN OUT gcmp::Vector3d& endPt);

        virtual void InitAction(gcmp::IUiView* pCurrentView) override;

        virtual gcmp::OwnerPtr<gcmp::IGraphicsElementShape> OnWallUpdate(gcmp::IUiView* pCurrentView, const gcmp::Vector3d& startPt, const gcmp::Vector3d& endPt);
    private:
        void OnPointUpdate(gcmp::IUiView* pCurrentView, const gcmp::Vector3d& pickedPt, const gcmp::Vector3d& mousePos);
    private:
        DrawStatus m_drawStatus;    //绘制状态
        gcmp::Vector3d m_ptStart;   //捕捉到的起始点
        gcmp::Vector3d m_ptEnd;     //捕捉到的终止点
        std::vector<gcmp::Vector3d> m_pickedPoints;
        bool m_isUserCancelled;
        gcmp::OwnerPtr<gcmp::ISnap> m_opSnapStart;
        gcmp::OwnerPtr<gcmp::ISnap> m_opSnapEnd;
        gcmp::OwnerPtr<gcmp::ISnapSettings> m_opOldSetting;
    };
}
